package com.denlaku.longan.controller.impl;

import com.denlaku.longan.controller.ObjectTagController;
import com.denlaku.longan.http.Resp;
import com.denlaku.longan.http.Return;
import com.denlaku.longan.qo.ObjPermQuery;
import com.denlaku.longan.qo.Query;
import com.denlaku.longan.service.ObjectTagService;
import com.denlaku.longan.util.SnowflakeUtils;
import com.denlaku.longan.vo.ObjectTag;
import com.denlaku.longan.vo.PageBy;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author tianx
 */
@RestController
public class ObjectTagControllerImpl implements ObjectTagController {
    @Autowired
    private ObjectTagService objPermTagService;

    @Override
    public Return<Void> add(ObjectTag objectTag) {
        objectTag.setId(SnowflakeUtils.nextId());
        objPermTagService.add(objectTag);
        return Resp.success();
    }

    @Override
    public Return<Void> update(ObjectTag objectTag) {
        objPermTagService.update(objectTag);
        return Resp.success();
    }

    @Override
    public Return<ObjectTag> get(Query query) {
        ObjectTag objectTag = objPermTagService.get(query);
        return Resp.success(objectTag);
    }

    @Override
    public Return<List<ObjectTag>> pageList(Query query, PageBy pageBy) {
        PageHelper.startPage(pageBy.getPage(), pageBy.getSize());
        List<ObjectTag> list = objPermTagService.list(query);
        return Resp.success(list);
    }

    @Override
    public Return<List<ObjectTag>> search(Query query) {
        List<ObjectTag> list = objPermTagService.search(query);
        return Resp.success(list);
    }

    @Override
    public Return<Void> delete(ObjPermQuery query) {
        if (query.getId() != null) {
            objPermTagService.delete(query);
        }
        return Resp.success();
    }
}
